package com.lz.spring.cloud.study;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

/**
 * 应用启动入口类
 * @author likejian
 *
 */
@SpringBootApplication
public class Application {

	protected static Logger LOGGER = LoggerFactory.getLogger(Application.class);
	
	
	public static void main(String[] args) throws Exception {
		LOGGER.info("=====开始启动===============");
		SpringApplication.run(Application.class, args);
		initFlowRules();
		LOGGER.info("=====启动完成=====");
	}

	private static void initFlowRules(){
		List<FlowRule> rules = new ArrayList<>();
		FlowRule rule = new FlowRule();
		rule.setResource("HelloWorld");
		rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
		// Set limit QPS to 20.
		rule.setCount(20);
		rules.add(rule);
		FlowRuleManager.loadRules(rules);
	}
}
